﻿using System;
using System.Data;
using System.Configuration;
using System.Web;

using System.Xml;
using System.IO;
using HtmlAgilityPack;
using Newtonsoft;
using System.Text;
using System.Net;
/// <summary>
/// Summary description for ExchangeVietComBank
/// </summary>
/// 
namespace WorldExchange
{
    public class ExchangeTechComBank : Exchange
    {
        public ExchangeTechComBank()
        {
            this.LinkService =ConfigurationSettings.AppSettings["Techcombank"].ToString();
        }
        public ExchangeTechComBank(string pUrl)
        {
            this.LinkService = pUrl;
        }
        #region "Method"
        public override void getExchange()
        {
           Boolean ret = true;
           
                # region "Gán Giá trị"
                Price a = new Price();
                a.Ma = "";
                a.Mua_CK = "";
                a.Mua_TM = "";
                a.Ban = "";
                AUD = a;
                CAD = a;
                CHF = a;
                DKK = a;
                EUR = a;
                GBP = a;
                HKD = a;
                INR = a;
                JPY = a;
                KRW = a;
                KWD = a;
                MYR = a;
                NOK = a;
                SEK = a;
                SGD = a;
                THB = a;
                USD = a;
                #endregion
                XmlDocument xmldoc = new XmlDocument();
                try
                {
                    //VNS.Web.HttpWeb webGet = new VNS.Web.HttpWeb();
                    string strXML = WebTool.getWebClient(this.LinkService);
                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(strXML);
                    HtmlNode node = doc.GetElementbyId("table1");

                    HtmlNodeCollection listnode = node.SelectNodes("//tr");

                    # region "Gán Giá trị"
                    Price TempAUD = new Price();
                    TempAUD.Ma = node.ChildNodes[1].ChildNodes[19].ChildNodes[1].InnerText.Trim().ToString();
                    TempAUD.Mua_CK = node.ChildNodes[1].ChildNodes[19].ChildNodes[3].InnerText.Trim().ToString();
                    TempAUD.Mua_TM = node.ChildNodes[1].ChildNodes[19].ChildNodes[5].InnerText.Trim().ToString();
                    TempAUD.Ban = node.ChildNodes[1].ChildNodes[19].ChildNodes[7].InnerText.Trim().ToString();
                    
                    AUD = TempAUD;

                    Price TempCAD = new Price();
                    TempCAD.Ma = node.ChildNodes[1].ChildNodes[21].ChildNodes[1].InnerText.Trim().ToString();
                    TempCAD.Mua_CK = node.ChildNodes[1].ChildNodes[21].ChildNodes[3].InnerText.Trim().ToString();
                    TempCAD.Mua_TM = node.ChildNodes[1].ChildNodes[21].ChildNodes[5].InnerText.Trim().ToString();
                    TempCAD.Ban = node.ChildNodes[1].ChildNodes[21].ChildNodes[7].InnerText.Trim().ToString(); 
                    CAD = TempCAD;

                    Price TempCHF = new Price();
                    TempCHF.Ma = node.ChildNodes[1].ChildNodes[25].ChildNodes[1].InnerText.Trim().ToString();
                    TempCHF.Mua_CK = node.ChildNodes[1].ChildNodes[25].ChildNodes[3].InnerText.Trim().ToString();
                    TempCHF.Mua_TM = node.ChildNodes[1].ChildNodes[25].ChildNodes[5].InnerText.Trim().ToString();
                    TempCHF.Ban = node.ChildNodes[1].ChildNodes[25].ChildNodes[7].InnerText.Trim().ToString(); 
                    CHF = TempCHF;

                    
                    Price TempEUR = new Price();
                    TempEUR.Ma = node.ChildNodes[1].ChildNodes[29].ChildNodes[1].InnerText.Trim().ToString();
                    TempEUR.Mua_CK = node.ChildNodes[1].ChildNodes[29].ChildNodes[3].InnerText.Trim().ToString();
                    TempEUR.Mua_TM = node.ChildNodes[1].ChildNodes[29].ChildNodes[5].InnerText.Trim().ToString();
                    TempEUR.Ban = node.ChildNodes[1].ChildNodes[29].ChildNodes[7].InnerText.Trim().ToString(); 
                    EUR = TempEUR;

                    Price TempGBP = new Price();
                    TempGBP.Ma = node.ChildNodes[1].ChildNodes[23].ChildNodes[1].InnerText.Trim().ToString();
                    TempGBP.Mua_CK = node.ChildNodes[1].ChildNodes[23].ChildNodes[3].InnerText.Trim().ToString();
                    TempGBP.Mua_TM = node.ChildNodes[1].ChildNodes[23].ChildNodes[5].InnerText.Trim().ToString();
                    TempGBP.Ban = node.ChildNodes[1].ChildNodes[23].ChildNodes[7].InnerText.Trim().ToString(); 
                    GBP = TempGBP;

                    Price TempHKD = new Price();
                    TempHKD.Ma = node.ChildNodes[1].ChildNodes[31].ChildNodes[1].InnerText.Trim().ToString();
                    TempHKD.Mua_CK = node.ChildNodes[1].ChildNodes[31].ChildNodes[3].InnerText.Trim().ToString();
                    TempHKD.Mua_TM = node.ChildNodes[1].ChildNodes[31].ChildNodes[5].InnerText.Trim().ToString();
                    TempHKD.Ban = node.ChildNodes[1].ChildNodes[31].ChildNodes[7].InnerText.Trim().ToString(); 
                    HKD = TempHKD;

                    Price TempINR = new Price();
                    TempINR.Ma = node.ChildNodes[1].ChildNodes[15].ChildNodes[1].InnerText.Trim().ToString();
                    TempINR.Mua_CK = node.ChildNodes[1].ChildNodes[15].ChildNodes[3].InnerText.Trim().ToString();
                    TempINR.Mua_TM = node.ChildNodes[1].ChildNodes[15].ChildNodes[5].InnerText.Trim().ToString();
                    TempINR.Ban = node.ChildNodes[1].ChildNodes[15].ChildNodes[7].InnerText.Trim().ToString(); 
                    INR = TempINR;

                    Price TempJPY = new Price();
                    TempJPY.Ma = node.ChildNodes[1].ChildNodes[17].ChildNodes[1].InnerText.Trim().ToString();
                    TempJPY.Mua_CK = node.ChildNodes[1].ChildNodes[17].ChildNodes[3].InnerText.Trim().ToString();
                    TempJPY.Mua_TM = node.ChildNodes[1].ChildNodes[17].ChildNodes[5].InnerText.Trim().ToString();
                    TempJPY.Ban = node.ChildNodes[1].ChildNodes[17].ChildNodes[7].InnerText.Trim().ToString(); 
                    JPY = TempJPY;

                    Price TempKRW = new Price();
                    TempKRW.Ma = node.ChildNodes[1].ChildNodes[15].ChildNodes[1].InnerText.Trim().ToString();
                    TempKRW.Mua_CK = node.ChildNodes[1].ChildNodes[15].ChildNodes[3].InnerText.Trim().ToString();
                    TempKRW.Mua_TM = node.ChildNodes[1].ChildNodes[15].ChildNodes[5].InnerText.Trim().ToString();
                    TempKRW.Ban = node.ChildNodes[1].ChildNodes[15].ChildNodes[7].InnerText.Trim().ToString(); 
                    KRW = TempKRW;

                    Price TempKWD = new Price();
                    TempKWD.Ma = node.ChildNodes[1].ChildNodes[15].ChildNodes[1].InnerText.Trim().ToString();
                    TempKWD.Mua_CK = node.ChildNodes[1].ChildNodes[15].ChildNodes[3].InnerText.Trim().ToString();
                    TempKWD.Mua_TM = node.ChildNodes[1].ChildNodes[15].ChildNodes[5].InnerText.Trim().ToString();
                    TempKWD.Ban = node.ChildNodes[1].ChildNodes[15].ChildNodes[7].InnerText.Trim().ToString(); 
                    KWD = TempKWD;

                    Price TempMYR = new Price();
                    TempMYR.Ma = node.ChildNodes[1].ChildNodes[15].ChildNodes[1].InnerText.Trim().ToString();
                    TempMYR.Mua_CK = node.ChildNodes[1].ChildNodes[15].ChildNodes[3].InnerText.Trim().ToString();
                    TempMYR.Mua_TM = node.ChildNodes[1].ChildNodes[15].ChildNodes[5].InnerText.Trim().ToString();
                    TempMYR.Ban = node.ChildNodes[1].ChildNodes[15].ChildNodes[7].InnerText.Trim().ToString(); 
                    MYR = TempMYR;

                    Price TempNOK = new Price();
                    TempNOK.Ma = node.ChildNodes[1].ChildNodes[15].ChildNodes[1].InnerText.Trim().ToString();
                    TempNOK.Mua_CK = node.ChildNodes[1].ChildNodes[15].ChildNodes[3].InnerText.Trim().ToString();
                    TempNOK.Mua_TM = node.ChildNodes[1].ChildNodes[15].ChildNodes[5].InnerText.Trim().ToString();
                    TempNOK.Ban = node.ChildNodes[1].ChildNodes[15].ChildNodes[7].InnerText.Trim().ToString(); 
                    NOK = TempNOK;

                    Price TempSEK = new Price();
                    TempSEK.Ma = node.ChildNodes[1].ChildNodes[15].ChildNodes[1].InnerText.Trim().ToString();
                    TempSEK.Mua_CK = node.ChildNodes[1].ChildNodes[15].ChildNodes[3].InnerText.Trim().ToString();
                    TempSEK.Mua_TM = node.ChildNodes[1].ChildNodes[15].ChildNodes[5].InnerText.Trim().ToString();
                    TempSEK.Ban = node.ChildNodes[1].ChildNodes[15].ChildNodes[7].InnerText.Trim().ToString(); 

                    SEK = TempSEK;

                    Price TempSGD = new Price();
                    TempSGD.Ma = node.ChildNodes[1].ChildNodes[27].ChildNodes[1].InnerText.Trim().ToString();
                    TempSGD.Mua_CK = node.ChildNodes[1].ChildNodes[27].ChildNodes[3].InnerText.Trim().ToString();
                    TempSGD.Mua_TM = node.ChildNodes[1].ChildNodes[27].ChildNodes[5].InnerText.Trim().ToString();
                    TempSGD.Ban = node.ChildNodes[1].ChildNodes[27].ChildNodes[7].InnerText.Trim().ToString(); 

                    SGD = TempSGD;

                    Price TempTHB = new Price();
                    TempTHB.Ma = node.ChildNodes[1].ChildNodes[33].ChildNodes[1].InnerText.Trim().ToString();
                    TempTHB.Mua_CK = node.ChildNodes[1].ChildNodes[33].ChildNodes[3].InnerText.Trim().ToString();
                    TempTHB.Mua_TM = node.ChildNodes[1].ChildNodes[33].ChildNodes[5].InnerText.Trim().ToString();
                    TempTHB.Ban = node.ChildNodes[1].ChildNodes[33].ChildNodes[7].InnerText.Trim().ToString(); 
                    THB = TempTHB;

                    Price TempUSD = new Price();
                    TempUSD.Ma = node.ChildNodes[1].ChildNodes[15].ChildNodes[1].InnerText.Trim().ToString(); //listnode[17].ChildNodes[1].InnerText.Trim().ToString();
                    TempUSD.Mua_CK = node.ChildNodes[1].ChildNodes[15].ChildNodes[3].InnerText.Trim().ToString();
                    TempUSD.Mua_TM = node.ChildNodes[1].ChildNodes[15].ChildNodes[5].InnerText.Trim().ToString();
                    TempUSD.Ban = node.ChildNodes[1].ChildNodes[15].ChildNodes[7].InnerText.Trim().ToString();
                    USD = TempUSD;

                   
                   
                    #endregion

                   
                }
                catch (Exception ex)
                {
                    ret = false;
                    //throw ex;
                    //TLog.write();
                }
            //set lai value moi cho du lieu
                if (ret)
                    this.setNewValue();
            //return ret;
        }
        #endregion
    }
}